package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.core.FArray;
import com.fr.report.script.core.FunctionHelper;

public class SUMSQ extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    double d = 0.0D;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      if (paramArrayOfObject[i] == null)
        break label33:
      d += parseSQObject(paramArrayOfObject[i]);
    }
    label33: return FunctionHelper.parsePrimitiveDouble(d);
  }

  private double parseSQObject(Object paramObject)
  {
    if (paramObject instanceof Number)
      return (((Number)paramObject).doubleValue() * ((Number)paramObject).doubleValue());
    if (paramObject instanceof Boolean)
      return ((((Boolean)paramObject).booleanValue()) ? 1.0D : 0.0D);
    if (paramObject instanceof FArray)
    {
      FArray localFArray = (FArray)paramObject;
      double d = 0.0D;
      int i = 0;
      int j = localFArray.length();
      while (i < j)
      {
        d += parseSQObject(localFArray.elementAt(i));
        ++i;
      }
      return d;
    }
    try
    {
      return Double.parseDouble(paramObject.toString());
    }
    catch (NumberFormatException localNumberFormatException)
    {
    }
    return 0.0D;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "SUMSQ(number1,number2, ...):返回所有参数的平方和。\nnumber1, number2, ...:为 1 到 30 个需要求平方和的参数，也可以使用数组或对数组的引用来代替以逗号分隔的参数。\n示例:\nSUMSQ(3, 4) 等于 25\n";
  }

  public String getEN()
  {
    return "SUMSQ(number1,number2, ...): Returns the sum of the squares of the arguments.\nNumber1, number2, ... are 1 to 30 arguments for which you want the sum of the squares. You can also use a single array or a reference to an array instead of arguments separated by commas.\n\nExample:\n   SUMSQ(3, 4) = 25\n";
  }
}